﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace IGolovkine.AoA
{
    public static class StreamEx
    {
        public static byte[] ReadAllBytes(this Stream stream, int bufferLength)
        {
            byte[] buffer = new byte[bufferLength];
            using (MemoryStream ms = new MemoryStream())
            {
                int bytesRead = 0;
                do
                {
                    bytesRead = stream.Read(buffer, 0, buffer.Length);
                    if (bytesRead > 0)
                    {
                        ms.Write(buffer, 0, bytesRead);
                    }
                } while (bytesRead > 0);

                return ms.ToArray();
            }
        }
    }
}
